package com.example.jeudupendu;

import com.example.jeudupendu.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

	private ImageView imv_fond,imv_pendu;
	private LinearLayout lilay_jeu,lilay_affich;
	private EditText mot;
	private TextView mot_secret,aide;
	private Button btn_mot;
	private GridView gdv_button;
	private Controleur mon_controleur;
	private Context mon_context;
	private MenuItem mi_mot, mi_aide, mi_score;
	private boolean partie_encours = false, debut_jeu=false;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		mon_context = getApplicationContext();
		mon_controleur = new Controleur(mon_context);
		
		Button btn_mot=(Button) findViewById(R.id.button1);		
		btn_mot.setOnClickListener(btnclick);

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_main, menu);
		mi_mot = menu.getItem(1);
		mi_mot.setEnabled(false);
		mi_aide = menu.getItem(2);
		mi_aide.setEnabled(false);
		mi_score = menu.getItem(3);
		mi_score.setEnabled(false);

		return true;
		
	}
	

	private OnClickListener btnclick = new OnClickListener() 
	{
		public void onClick(View v) 
		{
			switch (v.getId())
			{
			case R.id.button1: 
				if(mon_controleur.demarre_partie() == "@Vide")
				{
					alertd("Alerte", "Pas de mots");
				}
				else
				{
					mot_secret.setText(mon_controleur.demarre_partie());	
				}
				break;

			}
		}
	};


	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.menu_new_partie: 
			if(!debut_jeu)
			{
				debutjeu();
			}
			if(!partie_encours)
			{
				partiedeb();
			}

			return true;
		case R.id.menu_vocale_mot: Toast.makeText(getApplicationContext(),	"clic sur mot",Toast.LENGTH_LONG).show();
		return true;
		case R.id.menu_aide : aide.setText(mon_controleur.retourne_aide());
		return true;
		case R.id.menu_score: Toast.makeText(getApplicationContext(),	"clic sur score",Toast.LENGTH_LONG).show();
		return true;

		default:
			return super.onOptionsItemSelected(item);
		}
	}

	private void alertd(String title,String msg)
	{
		AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
		builder.setMessage(msg)
		.setTitle(title);
		builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int id) {
				// User clicked OK button
			}
		});

		AlertDialog dialog = builder.create();
		dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);  
		dialog.show();

	}


	public void partiedeb(){
		debut_jeu = true;
		

	}

	public void partiefin(){
		partie_encours = false;
		gdv_button.setVisibility(View.GONE);
	}

	public void debutjeu(){
		
		imv_fond.setVisibility(View.GONE);
		mon_controleur.demarre_partie();
		partie_encours = true;
	}

	public void clic_aide(){

	}
}


